In [68]:
!cat index.yaml
In [65]:
!gcloud datastore --help
In [66]:
!gcloud datastore create-indexes --help
In [69]:
!gcloud datastore create-indexes index.yaml --quiet
In [70]:
!gcloud datastore cleanup-indexes index.yaml --quiet
In [ ]:
In [1]:
# import
from google.cloud import datastore
First you have to authenticate the google python library with
gcloud beta auth application-default login
In [ ]:
#client initialization
client=datastore.Client(project='future-sonar-168815')
In [2]:
#let's create an new entity
key=client.key('Art')
entity=datastore.Entity(key,exclude_from_indexes=['Title'])
print(entity)
In [19]:
#add some values
entity.update({'Title':'Sunrise Beach at Sunset',
'artist':'Pat Sumner',
'year':2012})
print(entity)
In [20]:
#put the new entity in the cloud datastore
client.put(entity)
In [23]:
#another one
key=client.key('Art')
entity=datastore.Entity(key,exclude_from_indexes=['Title'])
entity.update({'Title':'Laura near the Crossroads',
'artist':'K. Kim Jones',
'year':2015})
client.put(entity)
In [22]:
#another one
key=client.key('Art')
entity=datastore.Entity(key,exclude_from_indexes=['Title'])
entity.update({'Title':'Login / Logout',
'artist':'Pat Sumner',
'year':2008})
client.put(entity)
In [24]:
#let's make a query and have a look at the result
query=client.query(kind='Art',filters=[('artist','=','Pat Sumner')])
for result in query.fetch():
print(result)
In [63]:
# Let's delete them
query=client.query(kind='Art',filters=[('artist','=','Pat Sumner')])
client.delete_multi([result.key for result in query.fetch()])
In [82]:
#check if the deletes have been done correctly
query=client.query(kind='Art')
for result in query.fetch():
print(result)
In [ ]: